<html>
  <head>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
    <meta charset="UTF-8" />
    <title>test</title>
    <script src="./app.js"></script>
    <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
    <script>
      var vConsole = new window.VConsole();
    </script>
    <style>
      body {
        background: white;
        padding-top: env(safe-area-inset-top);
      }

      .item {
        margin: 16px;
        padding: 8px;
        border: 1px solid black;
        border-radius: 4px;
      }

      .item:active {
        background-color: bisque;
      }
    </style>
    <script>
      function testRequest() {
        app.request({
          baseUrl: "http://117.78.39.196:30888",
          url: "/ep-query/monitors",
          params: {
            days: 200,
          },
          success: (res) => {
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function testUploadFile() {
        const input = document.getElementById("test-file");
        console.log(input.files);

        if (input.files.length > 0) {
          var fReader = new FileReader();
          fReader.readAsDataURL(input.files[0]);
          fReader.onloadend = function (event) {
            console.log(event);
            const data = event.target.result;
            const startIndex = data.indexOf(",");

            app.request({
              baseUrl: "http://117.78.39.196:30888",
              url: "/user-center/user/file/user_group_pic",
              method: "post",
              data: [
                {
                  key: "files",
                  value: {
                    type: "image",
                    fileName: input.files[0].name,
                    data: data.slice(startIndex + 1),
                    mimeType: input.files[0].type,
                  },
                },
              ],
              success: (res) => {
                console.log(res);
              },
              fail: (error) => {
                console.log(error);
              },
              complete: () => {
                console.log("complete");
              },
            });
          };
        }
      }

      function testWindowOpen() {
        window.open(window.location.href, "", "width=100");
        // window.open("http://www.w3school.com.cn", "_blank", "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
      }

      function testWindowOpenNew() {
        window.open(window.location.href);
        // window.open("http://www.w3school.com.cn", "_blank", "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
      }

      function testWindowClose() {
        window.close();
      }

      function toast() {
        app.alert({
          message:
            "alert弹窗内容alert弹窗内容alert弹窗内容alert弹窗内容alert弹窗内容alert弹窗内容",
          success: (res) => {
            console.log(res.data.action); //confirm
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function toast_confirm() {
        app.confirm({
          message: "confirm弹窗内容",
          success: (res) => {
            console.log(res.data.action); //confirm cancel
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function toast_prompt() {
        app.prompt({
          message: "prompt弹窗内容",
          hint: "请输入...",
          defaultInput: "默认值",
          success: (res) => {
            console.log(res.data.action); //confirm cancel
            console.log(res.data.content); //输入框内容
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function getStatusBarHeight() {
        console.log(app.statusBarHeight);
      }

      function setRightMenus() {
        app.setRightMenus({
          data: [
            {
              icon: "icon,dotMore",
              children: [
                {
                  icon: "icon,share",
                  title: "分享",
                  onTap: (menuData) => {
                    share();
                  },
                },
              ],
            },
          ],
          success: (res) => {
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function refreshTrack() {
       app.postWebViewMessage({
          messageId:"refreshProjectGroup",
          data: {
            itemId: "34",
            value: 10,
          },
          success: (res) => {
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });

      }

      function share() {
        app.share({
          shareObject: {
            type: "url",
            title: "分享测试",
            description: "描述",
            url: "https://www.bing.com",
          },
          success: (res) => {
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function handleEsgDialog() {
        window.location.href = "app://handler/userCenter/presentEsg";
      }
    </script>
  </head>

  <body>
    <div class="item" onclick="testRequest()">
      app.request(Object object)测试
    </div>
    <div class="item" onclick="testUploadFile()">
      <input id="test-file" type="file" accept="image/*" />
      <button>上传文件</button>
    </div>
    <div class="item" onclick="testWindowOpen()">Window.open()</div>
    <div class="item" onclick="testWindowOpenNew()">Window.open() new</div>
    <div class="item" onclick="testWindowClose()">Window.close()</div>
    <div class="item" onclick="toast()">点击弹窗alert</div>
    <div class="item" onclick="toast_confirm()">点击弹窗confirm</div>
    <div class="item" onclick="toast_prompt()">点击弹窗prompt</div>
    <div class="item" onclick="getStatusBarHeight()">获取状态栏高度</div>
    <div class="item" onclick="setRightMenus()">setRightMenus</div>
    <div class="item" onclick="share()">分享</div>
    <div class="item" onclick="handleEsgDialog()">Esg推送弹出提醒</div>
    <div class="item" onclick="refreshTrack()">更新项目追踪</div>
  </body>
</html>
